﻿using EAS.Content.Buffs;
using EAS.Content.Projectiles;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace EAS.Content.Items
{
    public class CthulhuEmblem : ModItem
    {
        public override void SetDefaults()
        {
            Item.width = 28;
            Item.height = 28;
            Item.accessory = true;
            Item.value = 12400;
            Item.rare = ItemRarityID.Master;
            Item.master = true;
        }
        public override void SetStaticDefaults()
        {
            Item.ResearchUnlockCount = 1;
        }       
        public override void UpdateAccessory(Player player, bool hideVisual)
        {
            Rectangle playerRect = new((int)player.position.X - 150, (int)player.position.Y - 150, 300, 300);
            if (!hideVisual)
            {
                int debuffType = ModContent.BuffType<CustomDebuff>();
                for (int k = 0; k < 2; k++)
                {
                    Projectile.NewProjectile(null, player.Center.X, player.Center.Y, 0.0f, 0.0f, ModContent.ProjectileType<CthulhuEmblemProjectile>(), 0, 0.0f, player.whoAmI, k, 0.0f);
                }
                foreach (NPC npc in Main.npc)
                {
                    if (!npc.friendly && npc.active && Vector2.Distance(player.Center, npc.Center) <= 150f)
                    {                        
                        npc.AddBuff(debuffType, 60 * 5);
                    }
                }
            }
            player.dashDelay = (int)(player.dashDelay * 0.7f); 
        }
    }
}
